#include "../source/server.hpp"

void OnConnected(const Connection::ptr &conn) {
    LOG(LogLevel::INFO) << "NEW CONNECTION: " << conn.get();
}

void OnClosed(const Connection::ptr &conn) {
    LOG(LogLevel::INFO) << "CLOSE CONNECTION: " << conn.get();
}

void OnMessage(const Connection::ptr &conn, Buffer* buf) {
    LOG(LogLevel::INFO) << buf->ReadPosition();
    buf->MoveReadOffset(buf->ReadAbleSize());
    std::string str = "Hello";
    conn->Send(str.c_str(), str.size());
    // conn->Shutdown();       // 最后实际上是在handlewrite这里关闭连接的
}

int main()
{
    TcpServer server(8080);

    server.SetThreadCount(2);
    // server.EnableInactiveRelease(10);
    server.SetConnectedCallback(OnConnected);
    server.SetClosedCallback(OnClosed);
    server.SetMessageCallback(OnMessage);
    server.Start();

    return 0;
}